package com.tangsm.boot.demo.shiro.service.impl;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.stereotype.Service;

import com.tangsm.boot.demo.shiro.entity.UserInfo;
import com.tangsm.boot.demo.shiro.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	
	public UserInfo login(String username, String password) {
		//查库，然后匹配密码是否正确！

        if(!"tangsm".equals(username)) {
            // 抛出shiro异常，方便通知用户登录错误信息
            throw new UnknownAccountException("用户不存在");
        }
        if(!"123".equals(password)) {
            throw new IncorrectCredentialsException("密码错误");
        }

        UserInfo user = new UserInfo();
        user.setId(1L);
        user.setUsername("tangsm");
        user.setSign(String.format("欢迎 [%s] 登录系统", username));

        return user;
	}
}
